﻿using _2._17._2015_CodeFirst.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace _2._17._2015_CodeFirst.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            NameAddressViewModel model = new NameAddressViewModel();
            
            ContactsDbContext db = new ContactsDbContext();

            Name nick = db.Names
                .FirstOrDefault(n => n.FirstName == "nick"
                && n.LastName == "brittain");

            Address nicksBillingAddress = db.Addresses
                .FirstOrDefault(a => a.NameId == nick.NameId);

            model.Name = nick.FirstName + " " + nick.LastName;
            model.City = nicksBillingAddress.City;
            model.State = nicksBillingAddress.State;
            model.Street = nicksBillingAddress.Street;
            model.Zip = nicksBillingAddress.Zip;
            model.Type = nicksBillingAddress.AddressType.Type;

            return View(model);
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}